using System;
using System.Configuration;
using System.Data;
using digit.Core;

namespace SMS.SportService
{
    public class ServiceDetailsManager
    {
        #region CONSTRUCTORS
        static ServiceDetailsManager()
        {
            _data = new ServiceDetailsData(Util.GetConnectionString("SMSCSPORT"));
            _error = "";
        }
        #endregion

        #region ATTRIBUTES
        private static ServiceDetailsData _data;
        private static string _error;
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return _error;
            }
        }

        #endregion

        #region METHODS
        public static long Insert(string cmd1, string cmd2, string code1, string code2, string param1, string param2, string param3, string param4, string param5, string param6, string content1, string content2, string content3, string content4, string content5, string content6, byte msgType, byte contentType, byte numOfMsg, byte processType, string serviceId, string createdBy, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[24];
                values[0] = Util.ReplaceNullTo(cmd1, DBNull.Value);
                values[1] = Util.ReplaceNullTo(cmd2, DBNull.Value);
                values[2] = Util.ReplaceNullTo(code1, DBNull.Value);
                values[3] = Util.ReplaceNullTo(code2, DBNull.Value);
                values[4] = Util.ReplaceNullTo(param1, DBNull.Value);
                values[5] = Util.ReplaceNullTo(param2, DBNull.Value);
                values[6] = Util.ReplaceNullTo(param3, DBNull.Value);
                values[7] = Util.ReplaceNullTo(param4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(param5, DBNull.Value);
                values[9] = Util.ReplaceNullTo(param6, DBNull.Value);
                values[10] = Util.ReplaceNullTo(content1, DBNull.Value);
                values[11] = Util.ReplaceNullTo(content2, DBNull.Value);
                values[12] = Util.ReplaceNullTo(content3, DBNull.Value);
                values[13] = Util.ReplaceNullTo(content4, DBNull.Value);
                values[14] = Util.ReplaceNullTo(content5, DBNull.Value);
                values[15] = Util.ReplaceNullTo(content6, DBNull.Value);
                values[16] = Util.ReplaceNullTo(msgType, DBNull.Value);
                values[17] = Util.ReplaceNullTo(contentType, DBNull.Value);
                values[18] = Util.ReplaceNullTo(numOfMsg, DBNull.Value);
                values[19] = Util.ReplaceNullTo(processType, DBNull.Value);
                values[20] = Util.ReplaceNullTo(serviceId, DBNull.Value);
                values[21] = createdBy;
                values[22] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[23] = status;

                DataTable dTable = _data.Insert(values);
                if (dTable.Rows.Count < 1) return -1;

                return (long.Parse(dTable.Rows[0]["ServiceDetailID"].ToString()));
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return -1;
            }
        }

        public static long Insert(ServiceDetailsInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[24];
                values[0] = Util.ReplaceNullTo(info.Cmd1, DBNull.Value);
                values[1] = Util.ReplaceNullTo(info.Cmd2, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.Code1, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.Code2, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Param1, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Param2, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Param3, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Param4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Param5, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.Param6, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.Content1, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.Content2, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.Content3, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.Content4, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.Content5, DBNull.Value);
                values[15] = Util.ReplaceNullTo(info.Content6, DBNull.Value);
                values[16] = Util.ReplaceNullTo(info.MsgType, DBNull.Value);
                values[17] = Util.ReplaceNullTo(info.ContentType, DBNull.Value);
                values[18] = Util.ReplaceNullTo(info.NumOfMsg, DBNull.Value);
                values[19] = Util.ReplaceNullTo(info.ProcessType, DBNull.Value);
                values[20] = Util.ReplaceNullTo(info.ServiceID, DBNull.Value);
                values[21] = info.CreatedBy;
                values[22] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[23] = info.Status;

                DataTable dTable = _data.Insert(values);
                if (dTable.Rows.Count < 1) return -1;

                return (long.Parse(dTable.Rows[0]["ServiceDetailID"].ToString()));
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return -1;
            }
        }

        public static bool Update(long serviceDetailID, string cmd1, string cmd2, string code1, string code2, string param1, string param2, string param3, string param4, string param5, string param6, string param7, string content1, string content2, string content3, string content4, string content5, string content6, byte msgType, byte contentType, byte numOfMsg, byte processType, string createdBy, string serviceId, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[25];
                values[0] = serviceDetailID;
                values[1] = Util.ReplaceNullTo(cmd1, DBNull.Value);
                values[2] = Util.ReplaceNullTo(cmd2, DBNull.Value);
                values[3] = Util.ReplaceNullTo(code1, DBNull.Value);
                values[4] = Util.ReplaceNullTo(code2, DBNull.Value);
                values[5] = Util.ReplaceNullTo(param1, DBNull.Value);
                values[6] = Util.ReplaceNullTo(param2, DBNull.Value);
                values[7] = Util.ReplaceNullTo(param3, DBNull.Value);
                values[8] = Util.ReplaceNullTo(param4, DBNull.Value);
                values[9] = Util.ReplaceNullTo(param5, DBNull.Value);
                values[10] = Util.ReplaceNullTo(param6, DBNull.Value);
                values[11] = Util.ReplaceNullTo(content1, DBNull.Value);
                values[12] = Util.ReplaceNullTo(content2, DBNull.Value);
                values[13] = Util.ReplaceNullTo(content3, DBNull.Value);
                values[14] = Util.ReplaceNullTo(content4, DBNull.Value);
                values[15] = Util.ReplaceNullTo(content5, DBNull.Value);
                values[16] = Util.ReplaceNullTo(content6, DBNull.Value);
                values[17] = Util.ReplaceNullTo(msgType, DBNull.Value);
                values[18] = Util.ReplaceNullTo(contentType, DBNull.Value);
                values[19] = Util.ReplaceNullTo(numOfMsg, DBNull.Value);
                values[20] = Util.ReplaceNullTo(processType, DBNull.Value);
                values[21] = Util.ReplaceNullTo(serviceId, DBNull.Value);
                values[22] = createdBy;
                values[23] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[24] = status;

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(ServiceDetailsInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[25];
                values[0] = info.ServiceDetailID;
                values[1] = Util.ReplaceNullTo(info.Cmd1, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.Cmd2, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.Code1, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Code2, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Param1, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Param2, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Param3, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Param4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Param5, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.Param6, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.Content1, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.Content2, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.Content3, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.Content4, DBNull.Value);
                values[15] = Util.ReplaceNullTo(info.Content5, DBNull.Value);
                values[16] = Util.ReplaceNullTo(info.Content6, DBNull.Value);
                values[17] = Util.ReplaceNullTo(info.MsgType, DBNull.Value);
                values[18] = Util.ReplaceNullTo(info.ContentType, DBNull.Value);
                values[19] = Util.ReplaceNullTo(info.NumOfMsg, DBNull.Value);
                values[20] = Util.ReplaceNullTo(info.ProcessType, DBNull.Value);
                values[21] = Util.ReplaceNullTo(info.ServiceID, DBNull.Value);
                values[22] = info.CreatedBy;
                values[23] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[24] = info.Status;

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(long serviceDetailID)
        {
            _error = "";
            try
            {
                object[] values = { serviceDetailID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(ServiceDetailsInfo info)
        {
            _error = "";
            try
            {
                object[] values = { info.ServiceDetailID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static ServiceDetailsInfo Select(long serviceDetailID)
        {
            _error = "";
            try
            {
                object[] values = { serviceDetailID };
                DataTable dTable = _data.Select(values);
                if (dTable.Rows.Count < 1) return null;

                ServiceDetailsInfo info = new ServiceDetailsInfo(dTable.Rows[0]);
                return info;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            _error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAllLottery()
        {
            _error = "";
            try
            {
                return _data.SelectAllLottery();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SearchInfo(string Key)
        {
            _error = "";
            try
            {
                return _data.SearchInfo(Key);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectByCode(string Code)
        {
            _error = "";
            try
            {
                return _data.SelectByCode(Code);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        #endregion

    }
}